package com.example.demo.controller;

import com.example.demo.commen.AppResult;
import com.example.demo.commen.ResultCode;
import com.example.demo.exception.ApplicationException;
import com.example.demo.model.Board;
import com.example.demo.service.impl.BoardServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@Api(tags = "板块接口")
@RequestMapping("/board")
public class BoardController {

    @Value("${bit-forum.index.board-num:9}")
    private Long sum;
    @Autowired
    private BoardServiceImpl boardService;
    @RequestMapping(method = RequestMethod.GET,value = "/toplist")
    @ApiOperation("版块列表")
    public AppResult getBoardsBySum(){
        if(sum==null||sum<=0){
            throw  new ApplicationException(ResultCode.FAILED_PARAMS_VALIDATE.toString());
        }

      List<Board> list = boardService.getBoardsBySum(sum);
        if(list==null){
            list = new ArrayList<>();
        }
      return AppResult.success(list);
    }
}
